package com.lvchen.ui.twofunction;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lvchen.R;

import java.util.ArrayList;
import java.util.List;

/**
 * 功能二适配器
 */
public class TwoAdapter extends BaseAdapter{

    private Context context;
    private LayoutInflater mInflater;
    private List<String> dlist;

    public TwoAdapter(Context context,List<String> dlist){
        this.context = context;
        mInflater = LayoutInflater.from(context);
        setList(dlist);
    }

    public void setList(List<String> dlist){
        if(dlist!=null){
            this.dlist = dlist;
        }else {
            this.dlist = new ArrayList<String>();
        }
    }

    public void change(List<String> dlist){
        setList(dlist);
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return dlist.size();
    }

    @Override
    public Object getItem(int position) {
        return dlist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_two, null);
            viewHolder = new ViewHolder();
            viewHolder.tv_ft =(TextView)convertView.findViewById(R.id.tv_ft);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.tv_ft.setText(dlist.get(position).toString());

        return convertView;
    }


    private class ViewHolder {
        TextView tv_ft;
    }

}
